package servlet;

import common.framework.simplemvc.RequestMapping;
import common.utils.JSONUtil;
import common.utils.Result;
import entity.User;
import service.UserService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RequestMapping("/user")
public class UserServlet {

    UserService userService = new UserService();

    // 控制层 -》 业务层
    @RequestMapping("/insert.do")
    public String insert(HttpServletRequest req, HttpServletResponse res) {
        System.out.println("UserServlet.inset");
        return "hello";
    }

    @RequestMapping("/update.do")
    public void update(HttpServletRequest req, HttpServletResponse res) {
        System.out.println("UserServlet.update");
        JSONUtil.printByJSON(res, Result.success(""));
    }

    @RequestMapping("/delete.do")
    public void delete(HttpServletRequest req, HttpServletResponse res) {
        System.out.println("UserServlet.delete");
    }

    @RequestMapping("/select.do")
    public void select(HttpServletRequest req, HttpServletResponse res) {
        List<User> userList =  userService.selectList();
        JSONUtil.printByJSON(res, Result.success(userList));
    }
}
